﻿@page
@model FytSoa.Web.Pages.FytAdmin.Sys.RoleModifyModel
@{
ViewData["Title"] = "角色修改/添加";
Layout = "~/Pages/FytAdmin/_Layout.cshtml";
}
<style>
    .organize-tree {
        position: absolute;
        background-color: #fff;
        padding: 5px 15px;
        z-index: 1000;
        box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
        border-radius: 4px;
        opacity: 0;
        height: 0;
        display: none;
    }

    .organize-tree.active {
        display: block;
        opacity: 1;
        height: auto;
        max-height: 500px;
        overflow: auto;
        transition: all .5s;
    }
</style>
<div id="app">
    <form class="layui-form form-cus" action="" lay-filter="forms">
        <div class="layui-form-item">
            <label class="layui-form-label">角色组</label>
            <div class="layui-input-block">
                <select v-model="m.parentGuid" id="parentGuid" name="parentGuid" lay-filter="group" lay-verify="">
                    <option :value="it.guid" v-for="it in list">{{it.name}}</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属部门</label>
            <div class="layui-input-block">
                <input type="text" v-model="m.departmentName" name="DepartmentName" id="DepartmentName"
                    lay-verify="required" lay-verType="tips" autocomplete="off" placeholder="请选择所属部门"
                    class="layui-input">
                <div class="organize-tree">
                    <div id="tree" class="layui-tree-cus"></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input type="text" v-model="m.name" name="Name" lay-verify="required" lay-verType="tips"
                    autocomplete="off" placeholder="请输入角色名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否超管</label>
            <div class="layui-input-inline" style="width:80px;">
                <input type="checkbox" name="isSystem" lay-text="是|否" lay-skin="switch" lay-filter="switch">
            </div>
            <div class="layui-form-mid layui-word-aux">如果是超管，则不允许删除</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <div id="slideSort" style="top:17px;"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea v-model="m.summary" style="min-height: 60px;" name="Summary"
                    class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-cur-submit">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="submit" id="submit"><i
                        class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-hide"></i>立即提交</button>
                <button type="button" class="layui-btn layui-btn-primary btn-open-close">取消</button>
            </div>
        </div>
    </form>
</div>
@section Scripts{
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            m: {},
            list: []
        }
    });
    layui.config({
        base: '/themes/js/modules/'
    }).use(['layer', 'jquery', 'common', 'form', 'tree', 'slider'], function () {
        var form = layui.form, $ = layui.$, os = layui.common, tree = layui.tree
            , slider = layui.slider;
        var sliderIndex = slider.render({
            elem: '#slideSort'
            , input: true
            , change: function (value) {
                vm.m.sort = value;
            }
            , theme: '#409eff'
        });
        form.on('select(group)', function (data) {
            vm.m.parentGuid = data.value;
        });
        form.on('switch(switch)', function (data) {
            vm.m.isSystem = data.elem.checked;
        });
        var index = parent.layer.getFrameIndex(window.name);
        //监听提交
        form.on('submit(submit)', function (data) {
            if (!vm.m.parentGuid) {
                os.error('请选择角色组');
                return false;
            }
            $('#submit').attr('disabled', true).find('i').removeClass('layui-hide');
            var urls = "api/role/add";
            if (vm.m.guid) {
                urls = "api/role/edit";
            }
            os.ajax(urls, vm.m, function (res) {
                $('#submit').attr('disabled', false).find('i').addClass('layui-hide');
                if (res.statusCode === 200) {
                    parent.layer.close(index);
                } else {
                    os.error(res.message);
                }
            });
            return false;
        });
        $(".btn-open-close").on('click', function () {
            parent.layer.close(index);
        });
        //查询部门
        os.ajax('api/organize/gettree/', {}, function (res) {
            tree.render({
                elem: '#tree'
                , data: res
                , onlyIconControl: true
                , click: function (obj) {
                    guid = obj.data.id;
                    vm.m.departmentGuid = obj.data.id;
                    vm.m.departmentName = obj.data.title;
                    $(".organize-tree").removeClass('active');
                }
            });
        });
        //查询角色信息
        os.ajax('api/role/getpages/', { limit: 10000 }, function (res) {
            for (var i = 0; i < res.data.length; i++) {
                if (res.data[i].level == 0) {
                    vm.list.push(res.data[i]);
                }
            };
            vm.$nextTick(function () {
                //查询角色信息
                os.ajax('api/role/bymodel/', { parm: os.getUrlParam('guid') }, function (res) {
                    if (res.statusCode == 200) {
                        vm.m = res.data;
                        vm.m.level = 1;
                        sliderIndex.setValue(vm.m.sort);
                        $('#parentGuid').val(vm.m.parentGuid);
                        form.val("forms", {
                            "parentGuid": vm.m.parentGuid
                            , "isSystem": vm.m.isSystem
                        });
                    } else {
                        os.error(res.message);
                    }
                });
            });
        }, 'get');


        $("#DepartmentName").click(function () {
            $(".organize-tree").addClass('active');
        });
        $(".organize-tree").mouseleave(function () {
            $(".organize-tree").removeClass('active');
        });
    });</script>
}